<template>
  <el-dialog
    :visible.sync="visible"
    width="630px"
    :close-on-click-modal="false"
    @close="$emit('close')"
  >
    <!-- 使用slot自定义弹窗标题 -->
    <template slot="title">
      <div class="dialog-header-content">
        <img
          style="max-height: 17px; margin-right: 10px"
          src="@/assets/template/dialog-title.png"
          alt=""
        />
        <span class="dialog-title-text">金额支付</span>
      </div>
    </template>
    <!-- 支付界面 -->
    <div v-if="!showSuccessScreen" class="modal-body">
      <div class="payment-info-section">
        <!-- 金额显示区域 -->
        <div class="payment-amount-box">
          <div class="amount-text">
            <span class="amount-number">{{ finalPrice }}</span>
            <span class="amount-unit yuan">元</span>
            <span class="amount-unit">/3月</span>
          </div>
          <div class="amount-divider"></div>
          <div class="amount-desc">确认支付金额，完成支付！</div>
          <div class="amount-success">
            <img
              style="max-height: 30px"
              src="@/assets/template/sucess.png"
              alt=""
            />
          </div>
        </div>
        <div>
          <img
            style="max-height: 40px"
            src="@/assets/template/saomazhifu.png"
            alt=""
          />
        </div>

        <!-- 扫码支付区域 -->
        <div class="qr-code-section">
          <!-- <div class="qr-code-label">扫码支付</div> -->
          <!-- <div class="qr-code-dots">........</div> -->
          <div class="qr-code-image">
            <!-- 支付二维码 -->
            <QrcodeGenerator
              ref="customQrcode"
              :content="customQrcodeConfig.content"
              :size="customQrcodeConfig.size"
              :foreground-color="customQrcodeConfig.foregroundColor"
              :background-color="customQrcodeConfig.backgroundColor"
              :error-correction-level="customQrcodeConfig.errorCorrectionLevel"
            />
            <!-- <img src="@/assets/qrcode_service.png" alt="支付二维码" /> -->
          </div>
        </div>
      </div>

      <!-- 链接区域 -->
      <div class="links-section">
        <div class="link-item">公众号链接：</div>
        <div class="link-item">管理端链接：</div>
        <div class="login-tip">
          <i class="el-icon-info" style="color: #ff7d00; margin-right: 5px"></i>
          管理端的登录账号密码与您的微小猪登录账号密码相同，请直接使用！
        </div>
      </div>

      <!-- 付款按钮 -->
      <div class="payment-button-container">
        <el-button class="payment-done-btn" @click="handlePaymentDone">
          付款完成
        </el-button>
      </div>
    </div>

    <!-- 支付成功界面 - 新增区域 -->
    <div v-else class="success-container">
      <!-- 成功图标区域 -->
      <div class="success-icon-section">
        <img
          style="max-height: 200px; max-width: 240px"
          src="@/assets/template/pay_success.png"
          alt=""
        />
      </div>

      <!-- 分隔线 -->
      <div class="divider"></div>

      <!-- 链接信息区域 -->
      <div class="success-links-section">
        <div class="success-link-item">
          公众号链接：
          <span class="link-value">https://example.com/payment-confirm</span>
        </div>
        <div class="success-link-item">
          管理端链接：
          <span class="link-value">https://example.com/payment-confirm</span>
        </div>
      </div>
      <!-- 确认按钮 -->
      <div class="confirm-button-container">
        <el-button class="confirm-btn" @click="closeModal"> 确认 </el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "PaymentModal",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    finalPrice: {
      type: Number,
      default: 1599,
    },
    // 自定义二维码配置
    customQrcodeConfig: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      showSuccessScreen: false,
    };
  },
 
  methods: {
    handlePaymentDone() {
      // 显示支付成功界面
      this.showSuccessScreen = true;
      // 保留原有的emit事件，以便父组件可以处理支付完成事件
      // this.$emit("paymentDone");
    },
    closeModal() {
      // 关闭弹窗并重置状态
      this.showSuccessScreen = false;
      this.$emit("close");
      // 跳转productOpenwecart
      this.$router.push("/productOpenwecartBefore");
    },
  },
  watch: {
    // 监听visible变化，当弹窗重新打开时重置状态
    visible(newVal) {
      if (newVal === false) {
        this.showSuccessScreen = false;
      }
    },
  },
};
</script>

<style scoped>
/* 注意：如果使用scoped，需要使用/deep/穿透 */
::v-deep .el-dialog {
  border-radius: 15px;
  overflow: hidden;
}

/* 支付界面样式保持不变 */
.modal-body {
  padding: 17px 40px;
}

.payment-info-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.payment-amount-box {
  border: 2px solid #ff7d00;
  border-radius: 8px;
  padding: 20px 30px;
  position: relative;
  background-color: #fff;
}

.amount-text {
  font-size: 28px;
  font-weight: bold;
  margin-bottom: 10px;
  text-align: center;
}

.amount-number {
  font-size: 36px;
  font-weight: bold;
  color: #ff7d00;
}

.amount-unit.yuan {
  color: #323232 !important;
  font-size: 17px !important;
}

.amount-unit {
  font-size: 18px;
  margin-left: 5px;
  color: #ff7d00;
}

.amount-divider {
  height: 1px;
  background-color: #e8e8e8;
  margin-bottom: 10px;
}

.amount-desc {
  font-size: 12px;
  color: #666;
  text-align: center;
  padding: 10px 20px 0px 20px;
}

.amount-success {
  position: absolute;
  right: -2px;
  bottom: -2px;
}

.qr-code-section {
  text-align: center;
}

.qr-code-image img {
  width: 150px;
  height: 150px;
  border: 1px solid #eee;
}

.links-section {
  margin-bottom: 30px;
  padding-top: 20px;
}

.link-item {
  font-size: 12px;
  color: #666;
  margin-bottom: 10px;
}

.login-tip {
  font-size: 12px;
  color: #ff7d00;
  margin-top: 20px;
  display: flex;
  align-items: flex-start;
}

.payment-button-container {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

.payment-done-btn {
  background-color: #ff7d00;
  color: #fff;
  border: none;
  padding: 12px 40px;
  border-radius: 4px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
  width: 160px;
}

.payment-done-btn:hover {
  background-color: #ff6a00;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(255, 125, 0, 0.3);
}

.payment-done-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(255, 125, 0, 0.3);
}

/* 支付成功界面样式 - 新增样式 */
.success-container {
  text-align: center;
  position: relative;
}

.success-title {
  font-size: 24px;
  font-weight: bold;
  color: #ff7d00;
  margin-bottom: 50px;
}

.success-icon-section {
  position: relative;
  margin-bottom: 40px;
}

.arc {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  height: 100px;
  border: 2px solid #ffe4d0;
  border-bottom: none;
  border-radius: 100px 100px 0 0;
}

.dashed-line {
  width: 180px;
  height: 2px;
  background: linear-gradient(to right, #ff7d00 50%, transparent 50%);
  background-size: 10px 2px;
  background-repeat: repeat-x;
  margin: 0 auto;
}

/* 分隔线 */
.divider {
  height: 1px;
  background-color: #e8e8e8;
  margin: 20px 50px;
}

/* 链接信息区域 */
.success-links-section {
  text-align: left;
  margin-bottom: 40px;
  margin-left: 50px;
}

.success-link-item {
  margin-bottom: 15px;
  font-size: 12px;
  color: #666;
}

.link-value {
  color: #333;
  word-break: break-all;
}

/* 管理端步骤 */
.management-steps {
  margin-top: 10px;
  margin-left: 80px;
}

.step-item {
  font-size: 14px;
  color: #666;
  margin-bottom: 5px;
}

/* 确认按钮容器 */
.confirm-button-container {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

/* 确认按钮样式 */
.confirm-btn {
  background-color: #ff7d00;
  color: #fff;
  border: none;
  padding: 12px 40px;
  border-radius: 4px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s;
  width: 160px;
}

.confirm-btn:hover {
  background-color: #ff6a00;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(255, 125, 0, 0.3);
}

.confirm-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(255, 125, 0, 0.3);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .payment-info-section {
    flex-direction: column;
    gap: 20px;
  }

  .qr-code-image img {
    width: 120px;
    height: 120px;
  }

  .success-container {
    padding: 30px 20px;
  }

  .success-title {
    font-size: 20px;
  }

  .success-icon-circle {
    width: 100px;
    height: 100px;
  }

  .management-steps {
    margin-left: 0;
  }
}
</style>
